// pages/playlist-detail/index.js
import {
  getPlaylistDetail
} from '../../services/playlist-api'
import {getMusicDetail} from '../../services/music-api'
import {musicStore} from '../../store/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    playlistDetail:{},
    playlistSongs:[],
    statusBarHeight:getApp().globalData.statusBarHeight
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {id } = options
    this.setData({id})
    getPlaylistDetail(id).then(res => {
      const playlistDetail = res.playlist
      getMusicDetail(res.playlist.trackIds.map(item => item.id).join(',')).then(res => {
        const playlistSongs = res.songs
        this.setData({playlistSongs,playlistDetail})
      })
    })
    
  },
  playAllMusic(){
    const musicList = this.data.playlistDetail.trackIds.map((item) => {
      return item.id
    })
    wx.navigateTo({
      url: `/pages/music-detail/index?id=${musicList[0]}`
    })
    musicStore.dispatch('playAllMusicAction',musicList)
  }
})